<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <!--<el-form-item label="业务类型" prop="businessType">
        <el-select v-model="queryParams.businessType" placeholder="请选择业务类型" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>-->
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

     <el-form-item label="业务类型" prop="title">

        <el-select
              v-model="queryParams.businessType"
              placeholder="业务类型"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option
                v-for="dict in businessTypeOptions"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
      </el-form-item>


     <!-- <el-form-item label="发送时间" prop="senderTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.senderTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择发送时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!--<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>


    <el-table
      class="list-table"
      v-loading="loading"
      :data="taskList"
      stripe
      size="small"
      fit
      highlight-current-row
      style="width: 100%;">
      <!--<el-table-column type="selection" width="55" align="center"/>-->

			<el-table-column label="标题" align="left" prop="title" width="450"/>
      <el-table-column label="业务名称" align="center" prop="businessName" />
      <el-table-column label="发起部门" align="center" prop="startDeptName"/>

      <el-table-column label="发起人" align="center" prop="startUserName"/>

      <el-table-column label="发起时间" align="center" prop="startTime" width="180">

        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>

     <!-- <el-table-column label="接收人ID" align="center" prop="receiverId"/>-->
     <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wf:udited:history:query']"
          >审批记录
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

	<!-- 审批记录 -->
	 <el-dialog :title="title" :visible.sync="open" width="68%">

      <el-table
        class="list-table"
        v-loading="false"
        :data="historyList"
        stripe
        size="small"
        fit
        highlight-current-row

        style="width: 100%;">
      <!--  <el-table-column type="selection" width="55" align="center"/>-->
        <el-table-column label="审批单位" align="center" prop="auditDeptName" width="280"/>
        <el-table-column label="审批人" align="center" prop="auditerName" width="120"/>

        <el-table-column label="审批时间" align="center" prop="auditTime">
	        <template slot-scope="scope">
	          <span>{{ parseTime(scope.row.auditTime) }}</span>
	        </template>
	      </el-table-column>

        <el-table-column label="审批意见" align="center" prop="auditOpinion" />
        <el-table-column label="审批结果" align="center" prop="auditResult" >
        	<template slot-scope="scope">
	          <span v-html="formatterAuditResult(scope.row.auditResult)"></span>
	        </template>
        </el-table-column>

      </el-table>

      <div slot="footer" class="dialog-footer">


        <el-button @click="open = false">取消</el-button>
      </div>

    </el-dialog>

  </div>
</template>

<script>



  import { addTask, delTask, exportTask, getTask, listTask, updateTask,approval ,reject,test,listAll,historyList,auditedList } from '@/api/hr/task'

  export default {
    data() {
      return {
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 工作流待办事项表格数据
        taskList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          businessType: undefined,
          businessName: undefined,
          businessId: undefined,
          title: undefined,
          senderId: undefined,
          senderTime: undefined,
          receiverId: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {

        },

        businessTypeOptions : [],

        historyList : []

      }
    },
    created() {
      this.getList();

      //加载业务类型
			listAll().then(response => {

          if(response.code != '200'){
            this.msgError('后台请求出错，原因是' + response.msg)
            return;
          }
				this.businessTypeOptions = response.data;

        })

    },
    methods: {

			 formatterAuditResult(auditResult){
					  //'<font color=red><b>退回</b></font>' : '<font color=green><b>同意</b></font>'
					  if(auditResult == 1){
					  	return '<span style=\'background: green; color: #FFF; padding: 4px 6px; border-radius: 60px; margin-right: 5px;\'>同意</span>';
					  }else if(auditResult == 0){
					  		return '<span style=\'background: red; color: #FFF; padding: 4px 6px; border-radius: 60px; margin-right: 5px;\'>退回</span>';
					  }
				},

      /** 查询工作流待办事项列表 */
      getList() {
        //this.loading = true
        console.log('本次请求参数为:',this.queryParams);
        auditedList(this.queryParams).then(response => {
          //查询成功，返回数据，grid分页显示
          this.taskList = response.rows
          this.total = response.total
          this.loading = false
        })


      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          businessType: undefined,
          businessName: undefined,
          businessId: undefined,
          title: undefined,
          senderId: undefined,
          senderTime: undefined,
          receiverId: undefined,
          createTime: undefined
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset()
        this.open = true
        this.title = '添加工作流待办事项'
      },






      /** 审批按钮操作 */
      handleUpdate(row) {

        this.currentRow = row; //记录当前的行

        this.reset()
        const id = row.id || this.ids

        this.open = true
        this.title = '审批历史记录查询'
        historyList(id).then(response => {
          this.form = response.data
          this.open = true
          this.title = '审批历史记录查询'
          this.historyList = response.data

        })



      },

      handleExport() {
        const queryParams = this.queryParams
        this.$confirm('是否确认导出所有工作流待办事项数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return exportTask(queryParams)
        }).then(response => {
          this.download(response.msg)
        }).catch(function() {
        })
      }
    }
  }
</script>
